import sys
import traceback
from redis import Redis
from sqlalchemy.orm import Session
from app.common.enums import ErrTypes
from app.common.exceptions import GenericException
from app import utils
from app import services, schemas
from app.models import PayOrder,Factor, FactorFee
from app.config import conf
from app.models.trans_data import CardDailyTransData, CardMonthlyTransData
from app.services import trans_data

import logging
logger = logging.getLogger(__name__)

ACCOUNT_CENTER_URL = conf.SERVCIE_URLS.get('account-center') 


def update_card_trans_data(db: Session, r: Redis, new_order: PayOrder):
        logger.info('--> 更新卡交易数据')
        try:
            trans_data.cache_card_trans_date_data(r, new_order)
            trans_data.cache_card_trans_month_data(r, new_order)
            trans_data.add_card_trans_date_data(db, new_order)
            trans_data.add_card_trans_month_data
        except GenericException as err:
            logger.error(err.message)
            raise GenericException(err.error_type, message=err.message, data=err.data)
        except Exception as err:
            logger.error('初始化分润失败')
            exc_type, exc_value, exc_obj = sys.exc_info()
            traceback.print_exception(exc_type,exc_value,exc_obj,limit=3,file=sys.stdout)
            raise GenericException(ErrTypes.chn_trans_error)